﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using System.IO;

namespace GameUtils.GeneralObjects
{
    public static class AssetHelpers
    {
        #region Methods
        public static Dictionary<string, T> LoadContent<T>(this ContentManager pContentManager, string pContentFolder)
        {
            DirectoryInfo dir = new DirectoryInfo(pContentManager.RootDirectory + "\\" + pContentFolder);
            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            Dictionary<string, T> result = new Dictionary<string, T>();

            FileInfo[] files = dir.GetFiles("*.*");
            foreach (FileInfo file in files)
            {
                string key = Path.GetFileNameWithoutExtension(file.Name);
                result[key] = pContentManager.Load<T>(pContentFolder + key);
            }

            return result;
        }
        #endregion
    }
}